<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
<body>
<div class="layuimini-container layuimini-page-anim">
  <div class="layuimini-main">

    <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    <script type="text/html" id="currentTableBar">
      <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除评论</a>
    </script>

  </div>
</div>
<script>
  layui.use(['form', 'table','miniPage','element'], function () {
    var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;
    form.render();
    table.render({
      elem: '#currentTableId',
      url: '/adminCommentInfo',
      toolbar: '#toolbarDemo',
      defaultToolbar: ['filter', 'exports', 'print', {
        title: '提示',
        layEvent: 'LAYTABLE_TIPS',
        icon: 'layui-icon-tips'
      }],
      cols: [
        [
          {field: 'id', title: '评论编号', sort: true},
          {field: 'bookName', title: '书名', sort: true},
          {field: 'borrowerName', title: '评论人', sort: true},
          {field: 'score',title: '评分', sort: true},
          {field: 'content',minWidth: 400, title: '评论', sort: true},
          {title: '操作', minWidth: 200, toolbar: '#currentTableBar', align: "center"}
        ]
      ],
      limit: 15,
      page: true,
      skin: 'line'
    });


    table.on('tool(currentTableFilter)', function (obj) {
      var data = obj.data;
      if (obj.event === 'delete') {
        layer.confirm('真的要删除评论么', function (index) {
          $.ajax({
            url: '/deleteComment',
            type:'POST',
            data:{
              id:data.id,
              bookName:data.bookName,
              score:data.score
            },
            success:function (res){
              if(res.code==200){
                layer.close(index);
                layer.msg("删除成功!");
                parent.window.location.reload();
              }else {
                layer.msg(res.msg);
              }
            }

          })
        });
      } else if (obj.event === 'detail') {
        var content = miniPage.getHrefContent('/borrowerBooksDetail?name='+data.bookName);
        var index = layer.open({
          title: data.bookName,
          type: 1,
          shade: 0.2,
          maxmin:true,
          shadeClose: true,
          area: ['85%','75%'],
          content: content,
        });
        $(window).on("resize", function () {
          layer.full(index);
        });
        return false;
      } else if(obj.event === 'update'){
        var content = miniPage.getHrefContent('/borrowerCommentUpdate?id='+data.id);
        var index = layer.open({
          title: '评论修改',
          type: 1,
          shade: 0.2,
          maxmin:true,
          shadeClose: true,
          area: ['85%','75%'],
          content: content,
        });
        $(window).on("resize", function () {
          layer.full(index);
        });
        return false;
      }
      return false;
    });

  });
</script>
</body>
</html>

